//
//  CompanyTagsView.m
//  Btpin
//
//  Created by Vic on 2019/3/21.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "CompanyTagsView.h"

@implementation CompanyTagsView

- (instancetype)initWithFrame:(CGRect)frame dataArray:(NSArray *)dataArray {
    self = [super initWithFrame:frame];
    if (self) {
        [self initUIWithDataArray:dataArray];
    }
    return self;
}
- (void)initUIWithDataArray:(NSArray *)dataArray {
    self.backgroundColor = COLOR_OF_WHITE;
    UILabel *tagsLbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, 15*Scale, WIDTH-30*Scale, 30*Scale) text:@"公司福利" textColor:THEMECOLOR_OF_TEXT_333333 font:Font_20];
    [self addSubview:tagsLbl];
    tagsLbl.font = FontBold(Font_20);
    if (dataArray && dataArray.count) {
        UIScrollView *tagsScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, EndY(tagsLbl)+5*Scale, WIDTH-15*Scale, 35*Scale)];
        [self addSubview:tagsScrollView];
        CGFloat lblWidth = (WIDTH-40*Scale)*0.2;
        CGFloat endX = 0;
        for (NSInteger i = 0; i < dataArray.count; i++) {
            CGFloat textWidth = [UIToolsControl textWidth:dataArray[i] size:CGSizeMake(MAXFLOAT, CompanyTagsHeight) font:Font_13]+1;
            CGFloat width = ((lblWidth>textWidth)?lblWidth:textWidth);
            UILabel *lbl = [UIToolsControl initLabelWithFrame:CGRectMake(endX, 5*Scale, width, CompanyTagsHeight) text:dataArray[i] textColor:THEMECOLOR_OF_TEXT_666666 font:Font_13];
            lbl.textAlignment = NSTextAlignmentCenter;
            lbl.layer.cornerRadius = 2*Scale;
            lbl.layer.masksToBounds = YES;
            lbl.layer.borderColor = THEMECOLOR_OF_TEXT_cccccc.CGColor;
            lbl.layer.borderWidth = 0.5;
            [tagsScrollView addSubview:lbl];
            endX = EndX(lbl)+5*Scale;
        }
        tagsScrollView.contentSize = CGSizeMake(endX+15*Scale, 0);
    } else {
        UILabel *lbl = [UIToolsControl initLabelWithFrame:CGRectMake(0, EndY(tagsLbl)+5*Scale, WIDTH-15*Scale, 35*Scale) text:@"待完善" textColor:THEMECOLOR_OF_TEXT_666666 font:Font_15];
        [self addSubview:lbl];
    }
}

@end
